window.onload = getUsers();


function getUsers() {
	var request = '/WSI/show';
	var result = $.get(request).done(function(data) {
                fillUsers(data)
        }).fail(function() {
                console.log("Unable to perform request : " + request);
        })

}

function fillUsers(data) {
	
	

	var table = document.getElementById('users');
	
	var tbody = document.createElement("tbody");
    table.appendChild(tbody);
    
    var row = document.createElement("tr");
    
    var user = document.createElement("td");
    var finished = document.createElement("td");
    var date = document.createElement("td");
    
    user.appendChild(document.createTextNode("User"));
    finished.appendChild(document.createTextNode("Zapisano"));
    date.appendChild(document.createTextNode("Data"));
    
    row.appendChild(user);
    row.appendChild(finished);
    row.appendChild(date); 
    
    table.appendChild(row);
    
	
	var xmlrows = data.getElementsByTagName("user");
	
	for(var r=0; r < xmlrows.length; r++) {
	  
	    var xmlrow = xmlrows[r];	    
	    var row = document.createElement("tr");
	    
	    var user = document.createElement("td");
	    var finished = document.createElement("td");
	    var date = document.createElement("td");
	    
	    var answer = ""
	    if (xmlrow.getAttribute("finished")=="true"){
	    	answer="tak";
	    }
	    else {
	    	anser="nie";	    	
	    }
	    
	    var date1=""
    	if (xmlrow.getAttribute("finishDate")=="null"){
    		 date1="---------";
 	    }
 	    else {
 	    	date1=xmlrow.getAttribute("finishDate");   	
 	    }
	    
	    
	    user.appendChild(document.createTextNode(xmlrow.getAttribute("username")));
	    finished.appendChild(document.createTextNode(answer));
	    date.appendChild(document.createTextNode(date1));
	    
	    row.appendChild(user);
	    row.appendChild(finished);
	    row.appendChild(date);     
	    
	    table.appendChild(row);
	}

	
}





